import { NodeSize } from '../config'

export default function excelOutput(flow) {
  flow.register('ExcelOutput', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M290.133333 134.095238H243.809524v75.580952L117.028571 80.457143 85.333333 114.590476l126.780953 126.780953H134.095238v46.323809h156.038095zM772.87619 319.390476L731.428571 277.942857h-63.390476V214.552381l-41.447619-41.447619h-124.342857l-41.447619 41.447619h165.790476v104.838095H731.428571v490.057143H299.885714V375.466667l-41.447619 41.447619v433.980952h514.438095z'
            }
          ),
          h(
            'path',
            {
              fill: '#DBF3DB',
              d: 'M731.428571 809.447619V319.390476h-104.838095V214.552381h-165.790476l-160.914286 160.914286v433.980952H731.428571zM404.72381 387.657143h36.571428l63.390476 102.4 65.828572-102.4h36.571428l-82.895238 129.219047 85.333334 131.657143h-36.571429l-68.266667-104.838095-65.828571 102.4h-36.571429l85.333334-131.657143-82.895238-126.780952z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M438.857143 646.095238l65.828571-104.838095 68.266667 104.838095H609.52381l-85.333334-131.657143 82.895238-126.780952h-36.571428L504.685714 487.619048l-63.390476-99.961905h-36.571428l82.895238 126.780952-85.333334 131.657143z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          'Excel输出'
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
